package com.hospital.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi // 开启Swagger3.0（如果是2.x则用@EnableSwagger2）
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30) // 3.0版本用OAS_30，2.x用SWAGGER_2
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hospital.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    // 配置文档基本信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("医院管理系统API文档")
                .description("医院管理系统的接口说明文档")
                .version("1.0.0")
                .build();
    }
}